package com.example.sensorlist;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    private SensorManager mSensorManager;
    private List<Sensor> mSensorList;
    private TextView textView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView = findViewById(R.id.text);
        showSensorInfo();
    }

    private void showSensorInfo() {
        mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        if (mSensorManager == null){
            throw new UnsupportedOperationException();
        }
        mSensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL);
        for (Sensor sensor : mSensorList){
            String sensorName = sensor.getName();
            textView.append(sensorName + "\n");
        }
    }
}
 